package com.inforich.web.controller.report;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.utils.poi.ExcelUtil;
import com.inforich.report.IReportService;
import com.inforich.report.domain.ResourceBooking;
import com.inforich.report.domain.ResourceFilings;
import com.inforich.report.domain.ResourceLandInfo;
import com.inforich.report.domain.ResourceRubbishProduce;
import com.inforich.report.domain.ResourceRubbishTransport;
import com.inforich.report.domain.ResourceUnsign;
import com.inforich.report.domain.ResourceVehicleDetail;
import com.inforich.report.domain.ResourceVehicleMonth;
import com.inforich.report.domain.ResourceVehicleOut;
import com.inforich.report.domain.ResourceVehicleOutDetail;
import com.inforich.report.domain.ResourceVehicleOutTransport;
import com.inforich.report.utils.ReportExcelHelper;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 统计报表
 * @author: HJM
 * @date: 2023/7/4
 */
@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {

  @Autowired
  private IReportService reportService;

  /**
   * 1、资源化备案登记统计表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceFilings:list')")
  @GetMapping("/resourceFilings/list")
  public Page<ResourceFilings> listResourceFilings(Page<ResourceFilings> page,
      ResourceFilings resourceFilings) {
    Map<String, Object> map = beanToMap(resourceFilings);
    reportService.pageResourceFilings(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceFilings:list')")
  @PostMapping("/resourceFilings/export")
  public void exportResourceFilings(HttpServletResponse response, ResourceFilings resourceFilings) {
    Map<String, Object> map = beanToMap(resourceFilings);
    List<ResourceFilings> list = reportService.listResourceFilings(map);
    ExcelUtil<ResourceFilings> util = new ExcelUtil<>(ResourceFilings.class);
    util.exportExcel(response, list, "资源化备案登记统计表");
  }

  /**
   * 2、固废排放申报汇总表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceBooking:list')")
  @GetMapping("/resourceBooking/list")
  public Page<ResourceBooking> listResourceBooking(Page<ResourceBooking> page,
      ResourceBooking dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceBooking(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceBooking:list')")
  @PostMapping("/resourceBooking/export")
  public void exportResourceBooking(HttpServletResponse response, ResourceBooking dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceBooking> list = reportService.listResourceBooking(map);
    ExcelUtil<ResourceBooking> util = new ExcelUtil<>(ResourceBooking.class);
    util.exportExcel(response, list, "固废排放申报汇总表");
  }

  /**
   * 3、建筑垃圾产生量汇总表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceRubbishProduce:list')")
  @GetMapping("/resourceRubbishProduce/list")
  public Page<ResourceRubbishProduce> listResourceRubbishProduce(Page<ResourceRubbishProduce> page,
      ResourceRubbishProduce dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceRubbishProduce(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceRubbishProduce:list')")
  @PostMapping("/resourceRubbishProduce/export")
  public void exportResourceRubbishProduce(HttpServletResponse response,
      ResourceRubbishProduce dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceRubbishProduce> list = reportService.listResourceRubbishProduce(map);
    ExcelUtil<ResourceRubbishProduce> util = new ExcelUtil<>(ResourceRubbishProduce.class);
    util.exportExcel(response, list, "建筑垃圾产生量汇总表");
  }

  /**
   * 4、建筑垃圾运输信息统计表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceRubbishTransport:list')")
  @GetMapping("/resourceRubbishTransport/list")
  public Page<ResourceRubbishTransport> listResourceRubbishTransport(
      Page<ResourceRubbishTransport> page, ResourceRubbishTransport dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceRubbishTransport(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceRubbishTransport:list')")
  @PostMapping("/resourceRubbishTransport/export")
  public void exportResourceRubbishTransport(HttpServletResponse response,
      ResourceRubbishTransport dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceRubbishTransport> list = reportService.listResourceRubbishTransport(map);
    ExcelUtil<ResourceRubbishTransport> util = new ExcelUtil<>(ResourceRubbishTransport.class);
    util.exportExcel(response, list, "建筑垃圾运输信息统计表");
  }

  /**
   * 5、建筑垃圾进厂明细表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceVehicleDetail:list')")
  @GetMapping("/resourceVehicleDetail/list")
  public Page<ResourceVehicleDetail> listResourceVehicleDetail(
      Page<ResourceVehicleDetail> page, ResourceVehicleDetail dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceVehicleDetail(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceVehicleDetail:list')")
  @PostMapping("/resourceVehicleDetail/export")
  public void exportResourceVehicleDetail(HttpServletResponse response,
      ResourceRubbishTransport dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceVehicleDetail> list = reportService.listResourceVehicleDetail(map);
    ExcelUtil<ResourceVehicleDetail> util = new ExcelUtil<>(ResourceVehicleDetail.class);
    util.exportExcel(response, list, "建筑垃圾进厂明细表");
  }

  /**
   * 6、建筑垃圾进厂月度汇总表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceVehicleMonth:list')")
  @GetMapping("/resourceVehicleMonth/list")
  public Page<ResourceVehicleMonth> listResourceVehicleMonth(
      Page<ResourceVehicleMonth> page, ResourceVehicleMonth dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceVehicleMonth(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceVehicleMonth:list')")
  @PostMapping("/resourceVehicleMonth/export")
  public void exportResourceVehicleMonth(HttpServletResponse response,
      ResourceVehicleMonth dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceVehicleMonth> list = reportService.listResourceVehicleMonth(map);
    ExcelUtil<ResourceVehicleMonth> util = new ExcelUtil<>(ResourceVehicleMonth.class);
    util.exportExcel(response, list, "建筑垃圾进厂月度汇总表");
  }

  /**
   * 7、资源化企业再生产品月度信息汇总表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceLandInfo:list')")
  @GetMapping("/resourceLandInfo/list")
  public Page<ResourceLandInfo> listResourceLandInfo(
      Page<ResourceLandInfo> page, ResourceLandInfo dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceLandInfo(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceLandInfo:list')")
  @PostMapping("/resourceLandInfo/export")
  public void exportResourceLandInfo(HttpServletResponse response,
      ResourceLandInfo dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceLandInfo> list = reportService.listResourceLandInfo(map);
    ExcelUtil<ResourceLandInfo> util = new ExcelUtil<>(ResourceLandInfo.class);
    util.exportExcel(response, list, "资源化企业再生产品月度信息汇总表");
  }

  @PreAuthorize("@ss.hasPermi('report:resourceLandInfo:list')")
  @PostMapping("/resourceLandInfo/exportXls")
  public void exportResourceLandInfoXls(HttpServletResponse response,
      ResourceLandInfo dto) throws IOException {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceLandInfo> list = reportService.listResourceLandInfo(map);
    Workbook wb = ReportExcelHelper.createLandInfo(list);
    response.addHeader("Access-Control-Expose-Headers", "Content-Disposition,download-filename");
    response.setHeader("Content-Disposition",
        "attachment; filename=" + URLEncoder.encode("资源化企业再生产品月度信息汇总表.xls", "utf-8"));
    response.setContentType("application/octet-stream");
    response.setCharacterEncoding("utf-8");
    try {
      wb.write(response.getOutputStream());
    } finally {
      IOUtils.closeQuietly(wb);
    }
  }

  /**
   * 8、资源化企业出厂信息汇总表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceVehicleOut:list')")
  @GetMapping("/resourceVehicleOut/list")
  public Page<ResourceVehicleOut> listResourceVehicleOut(
      Page<ResourceVehicleOut> page, ResourceVehicleOut dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceVehicleOut(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceVehicleOut:list')")
  @PostMapping("/resourceVehicleOut/export")
  public void exportResourceVehicleOut(HttpServletResponse response,
      ResourceVehicleOut dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceVehicleOut> list = reportService.listResourceVehicleOut(map);
    ExcelUtil<ResourceVehicleOut> util = new ExcelUtil<>(ResourceVehicleOut.class);
    util.exportExcel(response, list, "资源化企业出厂信息汇总表");
  }

  /**
   * 10、资源化企业再生产品出厂信息明细表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceVehicleOutDetail:list')")
  @GetMapping("/resourceVehicleOutDetail/list")
  public Page<ResourceVehicleOutDetail> listResourceVehicleOutDetail(
      Page<ResourceVehicleOutDetail> page, ResourceVehicleOutDetail dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceVehicleOutDetail(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceVehicleOutDetail:list')")
  @PostMapping("/resourceVehicleOutDetail/export")
  public void exportResourceVehicleOutDetail(HttpServletResponse response,
      ResourceVehicleOutDetail dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceVehicleOutDetail> list = reportService.listResourceVehicleOutDetail(map);
    ExcelUtil<ResourceVehicleOutDetail> util = new ExcelUtil<>(ResourceVehicleOutDetail.class);
    util.exportExcel(response, list, "资源化企业出厂信息明细表");
  }

  /**
   * 9、资源化企业再生产品出厂运输表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceVehicleOutTransport:list')")
  @GetMapping("/resourceVehicleOutTransport/list")
  public Page<ResourceVehicleOutTransport> listResourceVehicleOutTransport(
      Page<ResourceVehicleOutTransport> page, ResourceVehicleOutTransport dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceVehicleOutTransport(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceVehicleOutTransport:list')")
  @PostMapping("/resourceVehicleOutTransport/export")
  public void exportResourceVehicleOutTransport(HttpServletResponse response,
      ResourceVehicleOutTransport dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceVehicleOutTransport> list = reportService.listResourceVehicleOutTransport(map);
    ExcelUtil<ResourceVehicleOutTransport> util = new ExcelUtil<>(
        ResourceVehicleOutTransport.class);
    util.exportExcel(response, list, "资源化企业再生产品出厂运输表");
  }


  /**
   * 11、报警信息汇总表
   */
  @PreAuthorize("@ss.hasPermi('report:resourceUnsign:list')")
  @GetMapping("/resourceUnsign/list")
  public Page<ResourceUnsign> listResourceUnsign(
      Page<ResourceUnsign> page, ResourceUnsign dto) {
    Map<String, Object> map = beanToMap(dto);
    reportService.pageResourceUnsign(page, map);
    return page;
  }

  @PreAuthorize("@ss.hasPermi('report:resourceUnsign:list')")
  @PostMapping("/resourceUnsign/export")
  public void exportResourceUnsign(HttpServletResponse response,
      ResourceUnsign dto) {
    Map<String, Object> map = beanToMap(dto);
    List<ResourceUnsign> list = reportService.listResourceUnsign(map);
    ExcelUtil<ResourceUnsign> util = new ExcelUtil<>(
        ResourceUnsign.class);
    util.exportExcel(response, list, "报警信息汇总表");
  }

}
